/********************************************************************************
 *    Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
 *                                                                              *
 *              This software is distributed under the terms of the * GNU Lesser
 *General Public Licence (LGPL) version 3,             * copied verbatim in the
 *file "LICENSE"                       *
 ********************************************************************************/
#ifndef HIMUSICUNPACKTASk_H
#define HIMUSICUNPACKTASk_H

// #include "TClonesArray.h"
#include "FairTask.h"
#include "HiDaqUnpackTask.h"

#include <string>
using std::string;

class TClonesArray;

class HiMusicUnpackTask : public FairTask {
public:
  /** Default constructor **/
  HiMusicUnpackTask();

  /** Constructor with parameters (Optional) **/
  HiMusicUnpackTask(HiDaqUnpackTask* BasicUnpacker, Bool_t savetotree);

  /** Destructor **/
  ~HiMusicUnpackTask();

  /** Initiliazation of task at the beginning of a run **/
  virtual InitStatus Init();

  /** ReInitiliazation of task when the runID changes **/
  virtual InitStatus ReInit();

  /** Executed for each event. **/
  virtual void Exec(Option_t *opt);

  /** Load the parameter container from the runtime database **/
  virtual void SetParContainers();

  /** Finish task called at the end of the run **/
  virtual void Finish();

  // Setters -----------------------

  // Getters -----------------------
  // Int_t GetTotalTSNum() const { return fMaxTSNum; }

  // Methods -----------------------

private:
  /** Input array from previous already existing data level **/
  //  TClonesArray* <InputDataLevel>;

  /** Output array to  new data level**/
  //  TClonesArray* <OutputDataLevel>;

  HiDaqUnpackTask* fBasicUnpacker{};  // 基本解包任务指针
  std::ifstream* fInputFile{};  // 原始文件流指针

  TClonesArray* fDaqInfoArray{};      // DAQ信息数组
  TClonesArray* fUnpackedArray{};      // 解包后数据数组

  std::vector<std::pair<uint64_t, uint64_t>> fTSAddressList; // 时间片-地址列表

  Bool_t fSaveToTree = kTRUE; // 是否保存到tree

  Int_t fCurrentTSIndex = 0;    // 当前处理时间片索引

  HiMusicUnpackTask(const HiMusicUnpackTask &);
  HiMusicUnpackTask operator=(const HiMusicUnpackTask &);

  ClassDef(HiMusicUnpackTask, 1);
};

#endif
